﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BasicParts;

namespace DialogMachine
{
    public enum SubAlignment
    {
        left,
        centre,
        right
    };
    public struct SubtitleSettings
    {
        /// <summary> Which alignment the subs use.</summary>
        public SubAlignment subAlignment;
        /// <summary> How far subs are indented, if they're not centre aligned.</summary>
        public int subIndent;
        /// <summary> The width of the screen, used for subs.</summary>
        public int screenWidth;
        /// <summary> How far from the bottom edge the subs are.</summary>
        public float subBottomSpacing;
        /// <summary> How far it is between every line of text in the subs.</summary>
        public float subRowSpacing;
        /// <summary> Whether to display subs or not.</summary>
        internal bool displaySubs;
        /// <summary> The various subtitle colors.</summary>
        public Dictionary<int, Color> subColors;

        /// <summary>
        /// All the settings used for subtitles.
        /// </summary>
        /// <param name="displaySubs">Whether to display subs or not.</param>
        /// <param name="screenWidth">The width of the screen, used for subs.</param>
        /// <param name="subAlignment">The alignment for subs.</param>
        /// <param name="subBottomSpacing">The distance from the bottom of the screen</param>
        /// <param name="subIndent">The distance from the edges of the screen.</param>
        /// <param name="subRowSpacing">The distance between rows.</param>
        public SubtitleSettings(bool displaySubs, int screenWidth,
            SubAlignment subAlignment, int subBottomSpacing,
            int subIndent, int subRowSpacing)
        {
            subColors = new Dictionary<int, Color>();
            this.displaySubs = displaySubs;
            this.screenWidth = screenWidth;
            this.subAlignment = subAlignment;
            this.subBottomSpacing = subBottomSpacing;
            this.subIndent = subIndent;
            this.subRowSpacing = subRowSpacing;
        }

        internal Vector2 FindSubPos(Line currentLine)
        {
            Vector2 pos = new Vector2(0, subBottomSpacing);
            switch (subAlignment)
            {
                case SubAlignment.left:
                    pos.X = subIndent;
                    break;
                case SubAlignment.centre:
                    //pos.X = Vattenspelet.camera.font.MeasureString(currentLine.line).X;
                    //pos.X = (Vattenspelet.camera.CameraSize.Width - pos.X) * 0.5f;
                    break;
                case SubAlignment.right:
                    pos.X = screenWidth - subIndent;
                    break;
                default: break;
            }
            if (currentLine.line.Contains("\n"))
                pos.Y -= subRowSpacing;
            return pos;
        }
    }
}